﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Abs.Core;

namespace Abs.App.Admin
{
    public partial class Manage_Users : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Kicks the non admin accounts out
            if (Session["Role"] == null)
                Response.Redirect("/User/Unauthorized_Access.aspx");
            if ((int)Session["Role"] == (int)Abs.Core.Models.User.RoleEnum.User)
                Response.Redirect("/User/Unauthorized_Access.aspx");

            var userManagement = Abs.Core.Management.Manage.User;
            IList<Abs.Core.Models.User.User> userList = userManagement.SelectAll();

            foreach (Abs.Core.Models.User.User user in userList)
            {
                TableRow row = new TableRow();
                for (int i = 0; i < 4; i++)
                {
                    TableCell cell = new TableCell();
                    if (i == 0)
                    {
                        Label label = new Label();
                        label.Text = user.Name.ToString();
                        cell.Controls.Add(label);
                    }
                    else if (i == 1)
                    {
                        Label label2 = new Label();
                        label2.Text = user.Email.ToString();
                        cell.Controls.Add(label2);
                    }
                    else if(i == 2)
                    {
                        HyperLink link = new HyperLink();
                        link.Text = "Edit";
                        link.NavigateUrl = "~/Admin/Edit_User.aspx?Email=" + user.Email.ToString();
                        cell.Controls.Add(link);
                    }
                    else
                    {
                        HyperLink link = new HyperLink();
                        link.Text = "Delete";
                        link.NavigateUrl = "~/Admin/Delete_User.aspx?Email=" + user.Email.ToString();
                        cell.Controls.Add(link);
                    }
                    row.Cells.Add(cell);
                    
                }
                             
                Table_Display.Rows.Add(row);
            }
        }
    }
}